﻿
Namespace Controls
	Public Class VolumeControl


		''' <summary>
		''' Sets whether the volume label is visible.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property VolumeLabelVisibility As Visibility
			Get
				Return GetValue(VolumeLabelVisibilityProperty)
			End Get

			Set(ByVal value As Visibility)
				SetValue(VolumeLabelVisibilityProperty, value)
			End Set
		End Property

		''' <summary>
		''' Represents the VolumeLabelVisibility Property.
		''' </summary>
		''' <remarks></remarks>
		Public Shared ReadOnly VolumeLabelVisibilityProperty As DependencyProperty = _
							   DependencyProperty.Register("VolumeLabelVisibility", _
							   GetType(Visibility), GetType(VolumeControl), _
							   New PropertyMetadata(Visibility.Visible))



		''' <summary>
		''' Sets whether the volume level label is visible.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property VolumeLevelVisibility As Visibility
			Get
				Return GetValue(VolumeLevelVisibilityProperty)
			End Get

			Set(ByVal value As Visibility)
				SetValue(VolumeLevelVisibilityProperty, value)
			End Set
		End Property

		''' <summary>
		''' Represents the VolumeLevelVisibility Property.
		''' </summary>
		''' <remarks></remarks>
		Public Shared ReadOnly VolumeLevelVisibilityProperty As DependencyProperty = _
							   DependencyProperty.Register("VolumeLevelVisibility", _
							   GetType(Visibility), GetType(VolumeControl), _
							   New PropertyMetadata(Visibility.Visible))




		''' <summary>
		''' The text to display on the volume control text label.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property LabelText As String
			Get
				Return GetValue(LabelTextProperty)
			End Get

			Set(ByVal value As String)
				SetValue(LabelTextProperty, value)
			End Set
		End Property

		Public Shared ReadOnly LabelTextProperty As DependencyProperty = _
							   DependencyProperty.Register("LabelText", _
							   GetType(String), GetType(VolumeControl), _
							   New PropertyMetadata("Volume"))





		''' <summary>
		''' The volume level of the control. Maximum of 1, minimum of 0.
		''' </summary>
		''' <value></value>
		''' <returns></returns>
		''' <remarks></remarks>
		Public Property Volume As Double
			Get
				Return GetValue(VolumeProperty)
			End Get

			Set(ByVal value As Double)
				SetValue(VolumeProperty, value)
			End Set
		End Property

		''' <summary>
		''' Represents the volume Property.
		''' </summary>
		''' <remarks></remarks>
		Public Shared ReadOnly VolumeProperty As DependencyProperty = _
							   DependencyProperty.Register("Volume", _
							   GetType(Double), GetType(VolumeControl), _
							   New PropertyMetadata(0.0))


		''' <summary>
		''' Captures the volume level and updates the text if the volume level text block is visible.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub VolumeSlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double)) Handles VolumeSlider.ValueChanged
			If VolumeLevelVisibility = Windows.Visibility.Visible Then
				VolumeLevel.Text = VolumeSlider.Value.ToString("P0")
			End If
		End Sub

		''' <summary>
		''' Handles raising and lowering the volume using the mouse wheel.
		''' </summary>
		''' <param name="sender"></param>
		''' <param name="e"></param>
		''' <remarks></remarks>
		Private Sub VolumeControl_PreviewMouseWheel(sender As Object, e As MouseWheelEventArgs) Handles Me.PreviewMouseWheel
			If e.Delta > 0 Then
				VolumeSlider.Value += 0.01
			ElseIf e.Delta < 0 Then
				VolumeSlider.Value -= 0.01
			End If
		End Sub
	End Class
End Namespace